﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using System.Data.SqlClient;




namespace BenhVien
{
    public partial class frm_ManagerStaff : Form
    {
        private Connection cons = new Connection();
        private DataTable dt = new DataTable();
        private SqlDataAdapter da = new SqlDataAdapter();
        public frm_ManagerStaff()
        {
            InitializeComponent();
        }
        
        private void displayRecord() {
            //Connect();
            Connection cons= new Connection();
            cons.Connect();
            dt = new DataTable();
            da = new SqlDataAdapter("Select * from NhanVien",cons.con);
            da.Fill(dt);

            dtGV_Staff.DataSource = dt.DefaultView;
          //  Disconnect();
        }
        private void getdata()
        {
            SqlCommand command = new SqlCommand();
            command.Connection = cons.con;
            command.CommandType = CommandType.Text;
            command.CommandText = @"Select 
                                            NhanVien.MaNV as N'MaNV',
                                            Ho as N'Ho',
                                            Ten as N'Ten',
                                            DiaChi as N'DiaChi',
                                            SoDienThoai as N'SoDienThoai',
                                            NgaySinh as N'NgaySinh',
                                            (Case GioiTinh when 1 Then N'Nam' else N'Nữ' end) as N'GioiTinh',
                                            MaBaoHiem as N'MaBaoHiem',
                                            Vitri as N'Vitri',
                                            Luong as N'Luong',
                                            BacLuong as N'BacLuong',
                                            MaPhong as N'MaPhong',
                                            SoGioLamTrongTuan as N'SoGioLamTrongTuan',
                                            HinhThucTraLuong as N'HinhThucTraLuong',
                                            HopDong as N'HopDong'
                                            From NhanVien";
            da.SelectCommand = command;
            da.Fill(dt);
            dtGV_Staff.DataSource = dt;
        }
        private void frm_ManagerStaff_Load(object sender, EventArgs e)
        {
            cons.Connect();
            //displayRecord();
            getdata();
            
        }

        private void btExit_Click(object sender, EventArgs e)
        {
            
            if (MessageBox.Show("Are you sure Exit", "Exit", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                cons.DisConnect();
                Close();
               // System.Windows.Forms.Application.Exit();
                //FormChinh _fmMain = new FormChinh();
                //_fmMain.Show();
            }

        }

        private void btAdd_Click(object sender, EventArgs e)
        {
            fmAddStaff _fmadd = new fmAddStaff();
            _fmadd.Show();
            Hide();
            //Dispose();
        }

        private void btEdit_Click(object sender, EventArgs e)
        {
            fmEditStaff _fmEditStaff = new fmEditStaff();
            _fmEditStaff.Show();
            Hide();
        }

        private void btSearch_Click(object sender, EventArgs e)
        {
            fmSearchStaff _fmSearchStaff = new fmSearchStaff();
            _fmSearchStaff.Show();
            Hide();
        }


        /*
         * private void button1_Click(object sender, EventArgs e)
        {
            

            //Create a dummy GridView
            
            //dtGV_Staff.AllowPaging = false;
            dtGV_Staff.DataSource = dt;
            //dtGV_Staff.DataBind();

            Response.Clear();
            Response.Buffer = true;
            Response.AddHeader("content-disposition",
             "attachment;filename=DataTable.xls");
            Response.Charset = "";
            Response.ContentType = "application/vnd.ms-excel";
            StringWriter sw = new StringWriter();
            HtmlTextWriter hw = new HtmlTextWriter(sw);

            for (int i = 0; i < GridView1.Rows.Count; i++)
            {
                //Apply text style to each Row
                GridView1.Rows[i].Attributes.Add("class", "textmode");
            }
            GridView1.RenderControl(hw);

            //style to format numbers to string
            string style = @"<style> .textmode { mso-number-format:\@; } </style>";
            Response.Write(style);
            Response.Output.Write(sw.ToString());
            Response.Flush();
            Response.End();
        }
         */

    }
}
